package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.SysPermissionQueryDTO;
import com.cddx.logistics.domain.pojo.SysPermission;
import com.cddx.logistics.domain.vo.SysPermissionVO;
import com.cddx.logistics.service.SysPermissionService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "菜单管理控制器")
@RequestMapping("/sysPermission")
public class SysPermissionController {

    @Resource
    private SysPermissionService sysPermissionService;
    @GetMapping("/queryPage")
    @ApiModelProperty("分页查询菜单")
    public R     queryPage(SysPermissionQueryDTO sysPermissionqueryDTO) {
        PageInfo<SysPermissionVO> pageInfo = sysPermissionService.queryPage(sysPermissionqueryDTO);
        return R.ok(pageInfo);
    }

    /**
     * 删除菜单
     */
    @GetMapping("/delete")
    @ApiModelProperty("删除菜单")
    public R     delete(Integer id) {
        return sysPermissionService.delete(id) ? R.ok("删除成功") : R.error("删除失败");
    }

    /**
     * 添加菜单
     */
    @PostMapping("/add")
    @ApiModelProperty("添加菜单")
    public R     add(SysPermission sysPermission) {
        return sysPermissionService.add(sysPermission) ? R.ok("添加成功") : R.error("添加失败");
    }

    /**
     * 修改菜单
     */
    @PostMapping("/update")
    @ApiModelProperty("修改菜单")
    public R     update(SysPermission sysPermission) {
        return sysPermissionService.update(sysPermission) ? R.ok("修改成功") : R.error("修改失败");
    }
}
